package StudyCode.summary.textfile;

import java.io.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetSourceCodeFromFile {
	public static void main(String[] argv) throws Exception {
		File file = new File(System.getProperty("user.dir") + "/src/StudyCode/summary/textfile/GetSourceCodeFromFile.java");
		System.out.println(getSourceCodeFromFile(file));
	}

	public static String getSourceCodeFromFile(File file) {
		String sourceCode = "";
		if (file == null) {
			return sourceCode;
		}
		try {
			Reader reader = new FileReader(file);
			sourceCode = getString(reader);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		return sourceCode;
	}

	private static String getString(Reader reader) throws IOException {
		String text = "";
		BufferedReader bufferedReader = new BufferedReader(reader);
		String line;
		while ((line = bufferedReader.readLine()) != null) {
			text += line + "\n";
		}
		return text;
	}
}
